﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.ViewModelGenerator.UnitTests
{
    [TestClass]
    public class TestSample4Tests
    {
        public TestSample4Tests()
        {
            // nothing
        }

        TestSample4 sample;

        [TestInitialize]
        public void TestInitialize()
        {
            this.sample = new TestSample4();
            this.propertyChanged = null;
        }

        [TestMethod]
        public void WrappedInt_Default()
        {
            Assert.AreEqual(6, this.sample.WrappedInt);
        }

        [TestMethod]
        public void WrappedInt_ChangeNotification()
        {
            this.sample.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(sample_PropertyChanged);

            this.sample.SetInt(234234);

            Assert.AreEqual("WrappedInt", this.propertyChanged);
            Assert.AreEqual(234234, this.sample.WrappedInt);
        }

        string propertyChanged;

        void sample_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (this.propertyChanged != null)
            {
                throw new Exception("Only support 1 property change at a time.");
            }

            this.propertyChanged = e.PropertyName;
        }

        [TestMethod]
        public void WrappedInt_ChangedMethod()
        {
            Assert.AreEqual(0, this.sample.WrappedIntChangedCallCount);

            this.sample.SetInt(123);

            Assert.AreEqual(1, this.sample.WrappedIntChangedCallCount);
            Assert.AreEqual(123, this.sample.WrappedInt);
        }

        [TestMethod]
        public void WrappedString_Default()
        {
            Assert.AreEqual("my string", this.sample.WrappedString);
        }

        [TestMethod]
        public void WrappedString_ChangeNotification()
        {
            this.sample.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(sample_PropertyChanged);

            this.sample.WrappedString = "blah";

            Assert.AreEqual("WrappedString", this.propertyChanged);
            Assert.AreEqual("blah", this.sample.WrappedString);
        }

        [TestMethod]
        public void WrappedString_ChangedMethod()
        {
            Assert.AreEqual(0, this.sample.WrappedStringChangedCallCount);

            this.sample.WrappedString = "foo";

            Assert.AreEqual(1, this.sample.WrappedStringChangedCallCount);
            Assert.AreEqual("foo", this.sample.WrappedString);
        }
    }
}
